/**
 * Created by luobo on 18/07/2017.
 */
function getJsonFromUrl(a) {
    var b = "";
    if (a) {
        if (!(a.split("?").length > 1))return "";
        b = a.split("?")[1]
    }
    b = location.search.substr(1);
    var c = {};
    return b.split("&").forEach(function (a) {
        var b = a.split("=");
        c[b[0]] = decodeURIComponent(b[1])
    }), c
}
var isNullObj = function (a) {
    for (var b in a)if (a.hasOwnProperty(b))return !1;
    return !0
}, superclass = function (a) {
    $.extend(this, a), this.init(), this.createItems instanceof Function && this.createItems(), this.initEvent instanceof Function && this.initEvent()
};
Date.prototype.pattern = function (a) {
    var b = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        S: this.getMilliseconds()
    }, c = "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_");
    /(y+)/.test(a) && (a = a.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))), /(E+)/.test(a) && (a = a.replace(RegExp.$1, (RegExp.$1.length > 1 ? RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468" : "") + c[this.getDay() + ""]));
    for (var d in b)new RegExp("(" + d + ")").test(a) && (a = a.replace(RegExp.$1, 1 == RegExp.$1.length ? b[d] : ("00" + b[d]).substr(("" + b[d]).length)));
    return a
}, String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "")
}, String.prototype.startsWith = function (a) {
    return this.match("^" + a) == a
}, String.prototype.endsWith = function (a) {
    return this.match(a + "$") == a
};
var sjApp = {
    htmlencode: function (a) {
        var b = document.createElement("div");
        return b.appendChild(document.createTextNode(a)), b.innerHTML
    },
    htmldecode: function (a) {
        if (!a)return "";
        var b = document.createElement("div");
        return b.innerHTML = a, b.innerText || b.textContent
    },
    getDomain: function () {
        return "http://" + window.location.host
    },
    validateUser: function () {
        return SJ_UT.id
    },
    toArray: function (a, b, c) {
        return Array.prototype.slice.call(a, b || 0, c || a.length)
    },
    format: function (a) {
        var b = sjApp.toArray(arguments, 1);
        return a.replace(/\{(\d+)\}/g, function (a, c) {
            return b[c]
        })
    },
    stringify: function (a) {
        return encodeURI(JSON.stringify(a))
    },
    autoHeight: function () {
        var a, b = 0, c = 0;
        if (this.length) {
            c = this.parent().height();
            for (var d = this; (a = d.prev()).length;)a.is(":hidden") || (b += a.height()), d = a
        }
        return c - b
    },
    getOtherImg: function (a) {
        var b = new RegExp('(?:(\\w+)":true,"){0,1}' + a + '(?:":true,"(\\w+)){0,1}'), c = this.cookieGet("otherImg");
        if (c)var d = c.match(b);
        var e = {};
        return d && (e.prev = d[1], e.next = d[2]), e
    },
    LR: function (a) {
        if (a) {
            var b = JSON.stringify(allImgIdJson),
                c = new RegExp('(?:(\\w+)":true,"){0,10}' + a + '(?:":true,"(\\w+)){0,10}'), d = b.match(c);
            d && this.cookieSet("otherImg", d[0])
        }
    },
    encodeUnicode: function (a) {
        return escape(a).toLocaleLowerCase().replace(/\%u/gi, "\\u")
    },
    curRecord: {size: 0},
    getImgUrl: function (a, b) {
        var c = "";
        if (b = b || "", a && a.url)try {
            var d = sjApp.ismobile ? "p1" : "p2";
            "string" == typeof a.url && (a.url = JSON.parse(a.url));
            var e = b.match(/^@(\d+)w_.*/);
            if (e) {
                var f = parseInt(e[1]);
                f > 2e3 ? d = sjApp.ismobile ? "p3" : "p5" : f < 600 ? d = "p1" : 900 == f && (d = "p3")
            }
            var g = b.match(/^@(\d+)h_.*/);
            if (g) {
                600 == parseInt(g[1]) && (d = "p2")
            }
            "p3" === b && (d = b), "p6" === b && (d = b), c = a.url[d] || ""
        } catch (a) {
        }
        return c
    },
    default_avatar: "/images/default_tx.png",
    user_avatar_error: function () {
        this.attr("src", sjApp.default_avatar), this.unbind("error")
    },
    user_avatar: function (a, b) {
        var c = sjApp.default_avatar;
        if (a && a.avatar && ("string" == typeof a.avatar && (a.avatar = JSON.parse(a.avatar)), c = a.avatar.a2 || a.avatar.a1 || c), this.error instanceof Function) {
            var d = this;
            d.error(function () {
                sjApp.user_avatar_error.call(d)
            })
        }
        return c
    },
    urlPath: function () {
        return "undefined" != typeof SJ_UT && SJ_UT.id, "/community/"
    }(),
    filterUrl: function (a) {
        return this.urlPath + a
    },
    userDetailUrl: function (a) {
        return this.urlPath + "user-details/" + (a || SJ_UT.id)
    },
    photoDetailUrl: function (a) {
        return this.urlPath + "photo-details/" + a
    },
    errorMsg: function (a) {
        if ("object" == typeof console && console.error instanceof Function && console.error(a.status + "**" + a.statusText + "**" + a.responseText), 0 == a.status) {
            var b = location.href;
            location.href = "http://usercenter.500px.me/login?service=" + b
        }
    },
    apply: function (a, b, c) {
        if (c && sjApp.apply(a, c), a && b && "object" == typeof b)for (var d in b)a[d] = b[d];
        return a
    },
    applyIf: function (a, b, c) {
        if (c && this.apply(a, c), a && b && "object" == typeof b)for (var d in b)void 0 === a[d] && (a[d] = b[d]);
        return a
    },
    cookieRemove: function (a, b) {
        $.cookie(a, "", {expires: -1, path: b || "/"})
    },
    cookieSet: function (a, b, c) {
        $.cookie(a, b, {path: c || "/"})
    },
    cookieGet: function (a, b) {
        var c = $.cookie(a);
        return "json" == b && (c = c ? JSON.parse(c) : {}), c
    },
    cookieSave: function (a) {
        var b = a.index, c = a.page || $.getUrlParam("page") || 1, d = a.size || $.getUrlParam("size") || 34;
        this.cookieSet(b + "_page", c, {path: "/"}), this.cookieSet(b + "_size", d, {path: "/"})
    },
    timeJson: {
        less_than_x_minutes: {one: "不足 1 分钟以前", other: "不足 {{count}} 分钟以前"},
        x_minutes: {one: "1 分钟前", other: "{{count}} 分钟以前"},
        about_x_hours: {one: "大约 1 小时以前", other: "大约 {{count}} 小时以前"},
        x_days: {one: "1 天前", other: "{{count}} 天以前"},
        about_x_months: {one: "大约 1 个月以前"},
        x_months: {other: "{{count}} 个月以前"},
        about_x_years: {one: "大约 1 年以前", other: "大约 {{count}} 年以前"},
        over_x_years: {one: "超过 1 年以前", other: "超过 {{count}} 年以前"},
        almost_x_years: {one: "将近 1 年以前", other: "将近 {{count}} 年以前"}
    },
    t: function () {
        var a = arguments[0];
        return arguments.length > 1 && (a = arguments[0].replace(/{{\S+}}/g, arguments[1].count)), a
    },
    time_ago_in_words: function (a) {
        var b, c, d, e, f, g, h, i;
        return g = a / 1e3, d = 60, c = 60 * d, b = 24 * c, e = 30.4 * b, f = 12 * e, .9 * d > g ? this.t(this.timeJson.less_than_x_minutes.one) : 1.5 * d > g ? this.t(this.timeJson.x_minutes.one) : 59.1 * d >= g ? this.t(this.timeJson.x_minutes.other, {count: Math.round(g / d)}) : 1.5 * c >= g ? this.t(this.timeJson.about_x_hours.one) : 23.1 * c >= g ? this.t(this.timeJson.about_x_hours.other, {count: Math.round(g / c)}) : 1.5 * b > g ? this.t(this.timeJson.x_days.one) : 29.1 * b > g ? this.t(this.timeJson.x_days.other, {count: Math.round(g / b)}) : 1.5 * e >= g ? this.t(this.timeJson.about_x_months.one) : 11.1 * e >= g ? this.t(this.timeJson.x_months.other, {count: Math.round(g / e)}) : 14.1 * e > g ? this.t(this.timeJson.about_x_years.one) : 21.1 * e >= g ? this.t(this.timeJson.over_x_years.one) : (i = Math.floor(g / f), h = (g - i * f) / e, 2 >= h ? this.t(this.timeJson.about_x_years.other, {count: i}) : 9.5 >= h ? this.t(this.timeJson.over_x_years.other, {count: i}) : this.t(this.timeJson.almost_x_years.other, {count: i + 1}))
    },
    showMsg: function (a) {
        var b = $("#msg_window");
        b.length && b.remove();
        var c = a.cls,
            d = ['<div id="msg_window" style="top: -36px;" class="msg ', c, '"><div class="inside">', a.html, '</div><a class="close_x" id="msg_close"></a></div>'],
            e = $(d.join(""));
        $(document.body).append(e);
        var f = function () {
            e.css("top", -36), setTimeout(function () {
                e.remove()
            }, 600)
        };
        $("#msg_close").click(f), setTimeout(function () {
            e.css("top", 0)
        }, 10), setTimeout(function () {
            f()
        }, 4e3)
    },
    resizePic: function (a, b, c) {
        var d = 0, e = 0;
        d = b, e = c;
        var f = parseFloat(d - 180), g = parseFloat(e - 240);
        (f > 0 || g > 0) && (f >= g ? (a.width = d * (180 / d), a.height = e * (180 / d)) : f < g && (a.width = d * (240 / e), a.height = e * (240 / e)))
    },
    loadJs: function (a, b, c, d) {
        "string" == typeof a && (a = [a]);
        var c = c || this, e = document.getElementsByTagName("head")[0], f = document.createDocumentFragment(),
            g = a.length, h = 0, i = this, j = function (b) {
                e.appendChild(i.buildScriptTag(a[b], k))
            }, k = function () {
                h++, g == h && "function" == typeof b ? b.call(c) : !0 === d && j(h)
            };
        if (!0 === d) j.call(this, 0); else {
            for (var l, m = 0; l = a[m]; m++)f.appendChild(this.buildScriptTag(l, k));
            e.appendChild(f)
        }
    },
    buildScriptTag: function (a, b) {
        var c = document.createElement("script");
        return c.type = "text/javascript", c.src = a, c.readyState ? c.onreadystatechange = function () {
            "loaded" != c.readyState && "complete" != c.readyState || (c.onreadystatechange = null, b())
        } : c.onload = b, c
    },
    loadCSS: function () {
        var a;
        return function (b, c) {
            var d = null;
            d = document.createElement("link"), d.type = "text/css", d.rel = "stylesheet", d.href = b, "function" == typeof c && (d.onload = c);
            var e = document.getElementsByTagName("head")[0];
            a ? (e.replaceChild(d, a), a = d) : a = e.appendChild(d)
        }
    }(),
    handlebarsUtils: function () {
        Handlebars.registerHelper("filterCommentDate", function (a, b) {
            return "string" == typeof a && -1 != a.indexOf("-") && (a = new Date(a.replace(/-/g, "/")).getTime()), sjApp.time_ago_in_words((new Date).getTime() - parseInt(a))
        }), Handlebars.registerHelper("filterCommentDateTitle", function (a, b) {
            return "string" == typeof a && -1 != a.indexOf("-") ? a : new Date(parseInt(a)).pattern("yyyy-MM-dd E hh:mm:ss")
        }), Handlebars.registerHelper("user_avatar", function (a, b, c) {
            return sjApp.user_avatar.apply(this, arguments)
        }), Handlebars.registerHelper("isOwnedByCurrentUser", function (a, b) {
            if (a)return a.id == SJ_UT.id ? b.fn(this) : void 0
        }), Handlebars.registerHelper("isNotOwnedByCurrentUser", function (a, b) {
            if (a)return a.id != SJ_UT.id ? b.fn(this) : void 0
        }), Handlebars.registerHelper("expression", function () {
            var exps = [];
            try {
                for (var arg_len = arguments.length, len = arg_len - 1, j = 0; j < len; j++)exps.push(arguments[j]);
                var result = eval(exps.join(" "));
                return result ? arguments[len].fn(this) : arguments[len].inverse(this)
            } catch (a) {
            }
        }), Handlebars.registerHelper("getImgUrl", function (a, b, c) {
            if (a)return sjApp.getImgUrl.apply(this, arguments)
        })
    },
    override: function (a, b) {
        if (b) {
            var c = a.prototype;
            sjApp.apply(c, b)
        }
    },
    extend: function () {
        var a = function (a) {
            for (var b in a)this[b] = a[b]
        }, b = Object.prototype.constructor;
        return function (c, d, e) {
            d instanceof Object && (e = d, d = c, c = e.constructor != b ? e.constructor : function () {
                arguments.callee.init instanceof Function && (arguments.callee.init.apply(this, arguments), arguments.callee.init = null), d.apply(this, arguments)
            });
            var f, g = function () {
            }, h = d.prototype;
            return g.prototype = h, f = c.prototype = new g, f.constructor = c, c.superclass = h, h.constructor == b && (h.constructor = d), c.override = function (a) {
                sjApp.override(c, a)
            }, f.superclass = f.supr = function () {
                return h
            }, f.override = a, sjApp.override(c, e), c.extend = function (a) {
                return sjApp.extend(c, a)
            }, c
        }
    }(),
    onpopstate: function (a) {
        if (null != window.history.state && a.state) {
            var b = $('a[href="' + a.state.href + '"]');
            b.length > 0 && b.click()
        }
    },
    load_comments_page: function () {
        var a;
        return {
            setHandler: function (b) {
                a = b
            }, init: function (b) {
                if ("load" != b.type) {
                    var c = $(this).attr("href");
                    if (window.history.pushState) {
                        var d;
                        d = c.match(/^\?/) ? window.location.pathname + c : c, window.location.pathname + window.location.search != d && window.history.pushState({href: c}, d, d)
                    }
                    c || (c = window.location.pathname + window.location.search), a instanceof Function && a(c), b && b.preventDefault()
                } else {
                    var c = window.location.pathname + window.location.search;
                    window.history.replaceState({href: c}, c, c), a instanceof Function && a(c)
                }
                return !1
            }
        }
    }(),
    formatFileSize: function (a) {
        if (!a)return "";
        return a / 1024 / 1024 > 1 ? Math.round(a / 1024 / 1024 * 100) / 100 + "MB" : a / 1024 > 1 ? Math.round(a / 1024 * 100) / 100 + "KB" : a + "B"
    }
};
Date.prototype.pattern = function (a) {
    var b = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        S: this.getMilliseconds()
    }, c = "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_");
    /(y+)/.test(a) && (a = a.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))), /(E+)/.test(a) && (a = a.replace(RegExp.$1, (RegExp.$1.length > 1 ? RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468" : "") + c[this.getDay() + ""]));
    for (var d in b)new RegExp("(" + d + ")").test(a) && (a = a.replace(RegExp.$1, 1 == RegExp.$1.length ? b[d] : ("00" + b[d]).substr(("" + b[d]).length)));
    return a
}, function () {
    if ("undefined" != typeof $) {
        $(function () {
            var a = $(".scroll_to_top");
            viewHeight = document.body.clientHeight > $(window).height() ? $(window).height() : document.body.clientHeight, a.length || (a = $('<div class="scroll_to_top"><span class="scroll-img"><svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><defs><style>.cls-1{fill:#a1a1a1;}</style></defs><title>未标题-1</title><path class="cls-1" d="M20,0L0,10.2829V40H40V10.2829ZM32.43921,25.69183a1.06461,1.06461,0,0,1-.63086-0.21008L20.03021,16.72247,8.25214,25.48175a1.06473,1.06473,0,0,1-1.52063-.13416,1.1081,1.1081,0,0,1,.25238-1.64111l12.41229-9.23407a1.06238,1.06238,0,0,1,1.2749,0L33.0766,23.70648a1.108,1.108,0,0,1,.44513.8877A1.09012,1.09012,0,0,1,32.43921,25.69183Z"/></svg></span></div>'), $(document.body).prepend(a)), $(window).scroll(function () {
                var b;
                $(window).height(), b = $(window).scrollTop() - viewHeight, 0 >= b ? a.removeClass("display") : a.addClass("display")
            }), a.click(function () {
                $("html, body").animate({scrollTop: 0}, 300)
            })
        });
        var e = $(document.body);
        $.getUrlParam = function (a) {
            var b = new RegExp("(^|&)" + a + "=([^&]*)(&|$)"), c = window.location.search.substr(1).match(b);
            return null != c ? window.unescape(c[2]) : ""
        }, $.replaceParamVal = function (oldUrl, paramName, replaceWith) {
            var re = eval("/(" + paramName + "=)([^&]*)/gi"), nUrl = oldUrl.replace(re, paramName + "=" + replaceWith);
            return nUrl
        }, $.hasParameter = function (a, b) {
            var c = new RegExp("(^|&)" + b + "=([^&]*)(&|$)"), d = a.match(c);
            return null != d ? unescape(d[2]) : null
        }
    }
    var ismobile = !(!navigator.userAgent.match(/Android/i) && !navigator.userAgent.match(/iPhone|iPod|iPad/i));
    sjApp.apply(sjApp, {
        ismobile: ismobile, initBodyClass: function () {
            ismobile && $(document.body).addClass("smartphone")
        }()
    }), $(document).ready(function () {
        ismobile && $("a").on("click touchend", function (a) {
            var b = $(this), c = b.attr("href");
            c && (window.location = c)
        })
    })
}();
var trackEventBaiDu = function (a, b, c, d) {
    _hmt.push(["_trackEvent", a, b, c, d])
};
setTimeout(function () {
    sjApp.loadJs(["//pv.sohu.com/cityjson?ie=utf-8", "//node.shijue.me/js/csdn/dataTracking.js?a=1", "//node.shijue.me/js/csdn/viewTracking.js?a=1"], function () {
    }, null, !0), sjApp.loadJs("//hm.baidu.com/hm.js?7acfbc4d7bdb93be5cf0ee26c52160bf"), $(".lybyTrack").click(function () {
        if ("undefined" != typeof lyby) {
            var a = $(this);
            lyby.track({text: a.text(), type: a.data("trackType")})
        }
    }), function (a, b, c, d, e, f, g) {
        a.GoogleAnalyticsObject = e, a[e] = a[e] || function () {
                (a[e].q = a[e].q || []).push(arguments)
            }, a[e].l = 1 * new Date, f = b.createElement(c), g = b.getElementsByTagName(c)[0], f.async = 1, f.src = "https://www.google-analytics.com/analytics.js", g.parentNode.insertBefore(f, g)
    }(window, document, "script", 0, "ga"), ga("create", "UA-88923473-1", "auto");
    var a;
    "undefined" != typeof VCG && VCG.userId && (a = VCG.userId), ga("set", "userId", a), ga("send", "pageview")
}, 100);
